# encoding: utf-8
# @project: st2111 
# @file: re_groups_named.py
# @time: 2023/4/13 14:41
# @author: abcque
# @license: (C) Copyright 2013-2021
# @contact: abcque@outlook.com
# @IDE: PyCharm
# @desc:
import re

from chapter5.regular_expression.testre.re_test_patterns import test_patterns

if __name__ == "__main__":
    text = 'This is some text -- with punctuation.'

    patterns = [
        r"^(?P<first_word>\w+)",
        r"(?P<last_word>\w+)\S*$",
        # (r"\bt(\w)+\b", "以字符 t 开头的词"),
        # (r"\b(\w)+t\b", "以字符 t 结尾的词"),
    ]

    for pattern in patterns:
        regex = re.compile(pattern)
        match = regex.search(text)
        print("'{}'".format(pattern))
        print('  ', match.groups())
        print('  ', match.groupdict())
        print()
